

package com.wtf.generator.common.sys;

import lombok.Data;
import lombok.ToString;

import java.io.Serializable;

/**
 * date: 2022/6/18 10:59
 * @author linhuanyou
 * @email 496558736@qq.com
 * @version 1.0
 */
@Data
@ToString
public class R<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	private int code;

	private T data; //返回值

	private String msg = "成功";

	public R<T> setData(T data) {
		this.data = data;
		return this;
	}

	public R() {
		this.code = 0 ;
		this.msg = "success";
	}
	
	public static <T> R<T> error() {
		return error(500, "未知异常，请联系管理员");
	}
	
	public static <T> R<T> error(String msg) {
		return error(500, msg);
	}
	
	public static <T> R<T> error(int code, String msg) {
		R<T> r = new R<T>();
		r.setCode(code);
		r.setMsg(msg);
		return r;
	}

	public static <T> R<T> ok(T data) {
		R<T> r = new R<T>();
		r.setData(data);
		return r;
	}
	
	public static <T> R<T> ok() {
		return new R<T>();
	}
}
